package com.edu.controller;

import com.edu.service.BookService;
import com.edu.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
@Controller
public class BookController {
    @Resource
    private BookService bookService;

    private ModelAndView mv = new ModelAndView();

    @RequestMapping("/getBook")
    public Object getBooks(){
        mv.addObject("books",bookService.getAllBooks());
        mv.setViewName("book/book.jsp");
        return mv;
    }

    @RequestMapping("/book/{bookId}")
    public Object getBook(@PathVariable("bookId") int bookId){
        mv.addObject("book",bookService.getBook(bookId));
        mv.setViewName("/book/bookdetail.jsp");
        return mv;
    }

}
